// 引入config
import config from './config'
export default function (url, data = {}, method = 'GET') {
    return new Promise((resolve, reject) => {
        wx.request({
            url: config.host + url,
            data,
            method,
            // 设置请求头
            header:{
                // 通过find方法找到对应的cookie
                
                cookie:wx.getStorageSync('cookies')?JSON.parse(wx.getStorageSync('cookies')).find(item=>item.indexOf('MUSIC_U')
                !== -1):''
            },
            success: (result) => {
                resolve(result.data)
                // 判断是否是登录,因为在登录那里设置了标识符
                if (data.isLogin) {
                    // 存储cookies
                    wx.setStorage({
                        key:'cookies',
                        data:JSON.stringify(result.cookies)
                    })
                }
            },
            fail: function (error) {
                reject(error)
            }
        })
    })
}
